package com.example.administrator.newjiajiesong.main.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.KeyEvent;
import android.view.View;
import android.view.animation.AlphaAnimation;


import com.example.administrator.newjiajiesong.MainActivity;
import com.example.administrator.newjiajiesong.R;
import com.example.administrator.newjiajiesong.base.BaseActivity;
import com.example.administrator.newjiajiesong.main.my.entity.ImgEntity;
import com.example.administrator.newjiajiesong.network.http.ApiUtils;
import com.example.administrator.newjiajiesong.network.http.ResponseBean;
import com.example.administrator.newjiajiesong.utils.checkVersionsUtils.ProfileSpUtils;

import java.io.Serializable;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;


/**
 * SplashActivity
 * (๑• . •๑)
 * 类描述: 启开页
 * Created by LeiXiaoXing on 2017/4/19 15:03
 */

public class SplashActivity extends BaseActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

//        if (ProfileSpUtils.getInstance().getGuidState()) {
//            intData((long) 1500);
//            new Timer().schedule(new TimerTask() {
//                @Override
//                public void run() {
//                    startActivity(MainActivity.class);
//                    finish();
//                }
//            }, 1500);
//        } else {
//            final Intent intent = new Intent(SplashActivity.this, GuideActivity.class);
//            new Timer().schedule(new TimerTask() {
//                @Override
//                public void run() {
//                    startActivity(intent);
//                    ProfileSpUtils.getInstance().saveGuideState(true);
//                    finish();
//                }
//            }, 1000);
////            initData();
//        }
        new Timer().schedule(
                new TimerTask() {
                    @Override
                    public void run() {
                        if (ProfileSpUtils.getInstance().getGuidState()) {
                            startActivity(MainActivity.class);
                        } else {
                            ProfileSpUtils.getInstance().saveGuideState(true);
                            startActivity(GuideActivity.class);
                        }
                        finish();
                    }
                }, 1500);


    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        //禁用返回
        return true;
    }

    /**
     * 初始化数据库等操作
     */
    private void intData(Long time) {
        //渐变动画
        View view = findViewById(R.id.view_warp);
        AlphaAnimation animation = new AlphaAnimation(0.3f, 1.0f);
        animation.setDuration(time);
        view.startAnimation(animation);
    }

//    private void initData() {
//        ApiUtils.getVipApi().getImgUrl("1")
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Observer<ResponseBean<List<ImgEntity>>>() {
//                    @Override
//                    public void onSubscribe(Disposable d) {
//
//                    }
//
//                    @Override
//                    public void onNext(ResponseBean<List<ImgEntity>> listResponseBean) {
//                        final Intent intent = new Intent(SplashActivity.this, GuideActivity.class);
//                        intent.putExtra("img", (Serializable) (listResponseBean.getData()));
//                        new Timer().schedule(new TimerTask() {
//                            @Override
//                            public void run() {
//                                startActivity(intent);
//                                ProfileSpUtils.getInstance().saveGuideState(true);
//                                finish();
//                            }
//                        }, 1000);
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//
//                    }
//
//                    @Override
//                    public void onComplete() {
//
//                    }
//                });
//    }
}
